<template>
	<view class="commit-card" v-for="(item,index) in cardData" :key="item.CommunityID || index">
		<view class="user-box" @click="gotoDetailsPage(item.CommunityID)">
			<view class="UserImage">
				<image class="Avatar" :src="imageUrl+item?.pub_img" mode="aspectFill"></image>
				<view class="Name">{{item.pub_nick_name}}</view>
			</view>
			<uni-icons type="more-filled" size="24"></uni-icons>
		</view>
		<view class="Content-title" @click="gotoDetailsPage(item.CommunityID)">{{item.trip_blog_title}}</view>
		<text class="Content-text" @click="gotoDetailsPage(item.CommunityID)">{{item.trip_blog_content}}</text>
		<view class="imageAll-box" @click="gotoDetailsPage(item.CommunityID)">
			<block v-for="(itemImg,inde) in item.img_list" :key="index">
				<image class="item-iameg" mode="aspectFill" :src="imageUrl+itemImg"></image>
			</block>
		</view>
		<view class="icon-box">
			<text class="Views">{{ item.blog_view || '0' }}次浏览</text>
			<view class="icon-item" @click="isLiack(item.CommunityID,index)">
				<uni-icons v-if="item.is_like==1" color="#fc394b" type="hand-up-filled" size="18"></uni-icons>
				<uni-icons v-if="item.is_like==0" type="hand-up" size="18"></uni-icons>
				<view class="iconNumber">{{item.blog_like}}</view>
			</view>
			<!-- 			<view class="icon-item" @click="isCollect(item.CommunityID,index)">
					<uni-icons v-if="item.is_collect==1" color="#fc394b" type="heart-filled" size="18"></uni-icons>
					<uni-icons v-if="item.is_collect==0" type="heart" size="18"></uni-icons>
					<view class="iconNumber">{{item.blog_collect}}</view>
				</view> -->
		</view>
	</view>
</template>

<script setup>
	import {watchEffect} from 'vue';
	import { imageUrl } from '@/config/request/request';
	import { PostLike } from '@/config/API/commit';
	// import { PostcommunityInfo } from '@/config/API/commit';
	import {routerGuard} from '@/config/RouteGuard.js'
	const props = defineProps({
		cardData: {
			type: Array,
			default: () => []
		},
	})
	watchEffect(()=>{
		console.log('父组件传过来的社区数据',props);
	})
	// 点赞
	const isLiack = async(id,index) =>{
		const data = await PostLike(id)
		console.log('是否点赞成功===>>',data)
		if(data.code==200){
			propos.cardData[index].is_like==0?propos.cardData[index].is_like=1:propos.cardData[index].is_like=0
			propos.cardData[index].is_like==1?propos.cardData[index].blog_like+=1:propos.cardData[index].blog_like-=1
		}else if(data.code==309){
			uni.clearStorageSync()
			uni.navigateTo({
				url: '/pages/Login/Login'
			});
		}
	}
	const gotoDetailsPage = (id) => {
		const url = `/pages/community/commitDetails?id=${id}`
		routerGuard(url);
	}
</script>

<style lang="scss" scoped>
.commit-card{
	width: 100%;
	min-height: 300rpx;
	.user-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		.UserImage{
			display: flex;
			align-items: center;
			gap: 20rpx;
			.Avatar{
				border-radius: 50%;
				width: 100rpx;
				height: 100rpx;
			}
			.Name{
				max-width: 65vw;
				font-size: 30rpx;
				color: #8f8f8f;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1; /* 设置最大行数 */
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
	}
	.Content-title{
		margin-top: 30rpx;
		font-size: 30rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2; /* 设置最大行数 */
		overflow: hidden;
		text-overflow: ellipsis;
		line-height: 1.5em; /* 每行的高度 */
		word-break: break-all; /* 防止长单词导致布局破坏 */
	}
	.Content-text{
		color: #333333;
		font-size: 28rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 4; /* 设置最大行数 */
		overflow: hidden;
		text-overflow: ellipsis;
		line-height: 1.5em; /* 每行的高度 */
		word-break: break-all; /* 防止长单词导致布局破坏 */
	}

	.imageAll-box {
		margin: 30rpx 0;
		display: flex;
		gap: 15rpx;
		flex-wrap: wrap;
		.item-iameg {
			border-radius: 14rpx;
			width: calc((100% - 30rpx) / 3);
			height: 190rpx;
		}
	}
	.icon-box{
		margin-top: 10rpx;
		justify-content: flex-end;
		display: flex;
		gap: 80rpx;
		align-items: center;
		.Views{
			font-size: 26rpx;
			color: #8f8f8f;
			font-family: 300;
			letter-spacing: 3rpx;
		}
		.icon-item{
			display: flex;
			align-items: center;
			.iconNumber{
				font-size: 26rpx;
			}
		}
	}
}
</style>